const React = require('react'); //组件


class Index extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }

  handleClick = () => {
    this.setState({
      count: this.state.count + 1
    });
  };

  render() {
    return /*#__PURE__*/React.createElement("h1", {
      onClick: this.handleClick
    }, this.state.count);
  }

}

const Http = require('http');

const {
  renderToString
} = require('react-dom/server');

console.log(renderToString( /*#__PURE__*/React.createElement(Index, null))); // 直出html字符串

Http.createServer((request, response) => {
  response.writeHead(200, {
    'Content-type': 'text/html'
  });
  const html = renderToString( /*#__PURE__*/React.createElement(Index, null));
  response.end(`<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>传统 ssr</title>
        </head>
        <body>
            <div id="root">
               ${html}
            </div>
        </body>
        </html>
    `);
}).listen(9091);
